﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using CloudShot.Editor;

namespace CloudShot.ViewModels
{
  //TODO almost the same as BackColor property
  class BorderPropertyHandler<T>: RadioButtonPropertyHandler<T>
  {
    private LineType? _lineType;

    public BorderPropertyHandler(Expression<Func<PropertiesFormViewModel, T>> expression)
      : base(expression)
    {
    }

    public override void SetViewModel(PropertiesFormViewModel viewModel)
    {
      base.SetViewModel(viewModel);

      if (viewModel != null)
      {
        _lineType = viewModel.LineType;
      }
    }

    protected override void PreviewInternal(T previewValue)
    {
      if (_lineType == LineType.None)
        ViewModel.LineType = LineType.Solid;
 
      base.PreviewInternal(previewValue);
    }


    protected override void ResetInternal()
    {
      if (_lineType == LineType.None)
        ViewModel.LineType = LineType.None;

      base.ResetInternal();
    }

    protected override void SetPropertyInternal(T value)
    {
      if (_lineType == LineType.None)
      {
        _lineType = ViewModel.LineType = LineType.Solid;
      }

      base.SetPropertyInternal(value);
    }
  }
}
